package com.ybchen.aop;

import com.ybchen.content.TraceContextHolder;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * @description: traceId aop
 * @author: alex
 * @create: 2024-10-20 20:09
 */
@Aspect
@Component
public class TraceIdAspect {

    @Around("execution(* com.ybchen..*(..))")
    public Object manageTraceId(ProceedingJoinPoint joinPoint) throws Throwable {
        TraceContextHolder.setTraceId();
        try {
            return joinPoint.proceed();
        } finally {
            TraceContextHolder.clear();
        }
    }
}
